package com.church.services;

import java.util.List;

import com.church.dao.UserDao;
import com.church.db.User;

public class UserServicesImpl implements UserServices {
	private UserDao userDao;

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public String register(User user) {
		if (userDao.findByName(user.getName()) == null) {
			userDao.add(user);
		} else {
			return "error";
		}
		return "success";
	}

	public String login(String name, String password) {
		User user = userDao.findByName(name);
		if (user.getPassword().equals(password)) {
			return "success";
		} else {
			return "error";
		}

	}

	@Override
	public User findUserByName(String name) {
		return userDao.findByName(name);
	}

	@Override
	public List<User> getUserList() {
		return userDao.getAllUser();
	}

	@Override
	public List<User> getUserListByGroup(String group) {
		return userDao.getUserByGroup(group);
	}

	@Override
	public User findUserById(long id) {
		return userDao.findById(id);
	}

	@Override
	public String update(User user) {
		userDao.update(user);
		return "success";
	}
}
